package algorithm.PrintColor;

public class PrintColor {

    public static int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
        int currColor = image[sr][sc];
        if (currColor != newColor) {
            draw(image, sr, sc, newColor, currColor);
        }
        return image;
    }

    public static void draw(int[][] image, int sr, int sc, int newColor, int oldColor) {
        if (sr < 0 || sr >= image.length || sc < 0 || sc >= image[0].length)
            return;
        if (image[sr][sc] != oldColor)
            return;

        image[sr][sc] = newColor;
        System.out.println(sr+ " - " + sc);
        for (int[] i : image) {
            for (int j : i)
                System.out.print(j);
            System.out.println();
        }

        draw(image, sr-1, sc, newColor, oldColor);
        draw(image, sr, sc-1, newColor, oldColor);
        draw(image, sr+1, sc, newColor, oldColor);
        draw(image, sr, sc+1, newColor, oldColor);
        return;
    }

    public static void main(String[] args) {
        int[][] img = new int[][] {{0,0,0}, {0,1,1}};
        floodFill(img, 0, 0, 1);
        for (int[] i : img) {
            System.out.println();
            for (int j : i)
                System.out.print(j);
        }
    }
}